<?php
namespace app\admin\controller;

use app\Ctl;
use think\Request;
use think\Db;

class Login extends Ctl
{
    public function index()
    {
        return view('index');
    }
    public function login()
    {
        $request = Request::instance()->post('data/a');
        if(!captcha_check($request['captcha'],'adminLogin')){
            show(1,'验证码错误');
        }
        //查询admin表数据
        $admin = model('admin')->check_login($request['account']);
        if( !$admin ){
            show(2,'账号或密码错误');//数据不存在
        }else{
            if( md5($request['pwd']) !== $admin['pwd'] ){
                show(2,'账号或密码错误');//密码不正确
            }else{
                session('admin_login',$admin);
                unset($admin);
                show(200,'欢迎回来!');//正确,跳到后台首页
            }
        }

    }//login end



} //class login end